<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;

class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private  $email;

    private  $content;

    private  $subject;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct( $email, $content, $subject)
    {
        $this->email = $email;
        $this->content = $content;
        $this->subject = $subject;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $email = $this->email;
        $subject = $this->subject;

        /*发送单条文本信息*/
//        Mail::raw('邮件测试', function($message){
//            $message->to('1090300992@qq.com');
//            $message->subject('啦啦网邮箱注册激活');
//        });
        /*发送视图View页面*/
        Mail::send(
            'admin.activemail',
            ['content' => $this->content],
            function ($message) use($email, $subject) {
                $message->to($email)->subject($subject);
            }
        );

        // Mail::failures() 返回的错误邮件信息,判断是否发送成功. (无错误信息,返回空数组)
        if(empty(Mail::failures())){
            echo '发送成功';
        }else{
            echo '发送失败';
        }
    }
}
